<!DOCTYPE html>
<html th:lang="${language}" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header(#{okr.my})" />
  <th:block th:include="include :: okr-css" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row" >
    <div class="col-sm-12 search-collapse collapse">
      <form id="okr_search_form">
        <div class="select-list hidden">
          <ul class="row">
            <li class="col-xs-12 col-sm-6 col-md-4 hidden">
              <label>周期ID：</label>
              <input type="text" name="cycleId"   id="cycleId"/>
            </li>
            <li class="col-xs-12 col-sm-6 col-md-4">
              <a class="btn btn-primary btn-rounded btn-sm"
                 onclick="$.table.search('okr_search_form')">
                <i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
      <div class="btn-group">
        <select class="form-control" data-style="btn-success"  id="cycleIdSelect"  th:onchange="changeCycleType()">
          <optgroup th:label="#{okr.yearChoice}">
            <div th:each="cycle : ${cycleList}">
              <div th:if="${cycle.cycleType == 1}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
              </div>
            </div>
          </optgroup>
          <optgroup th:label="#{okr.quarterChoice}">
            <div th:each="cycle : ${cycleList}">
              <div th:if="${cycle.cycleType == 0}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
              </div>
            </div>
          </optgroup>
        </select>
      </div>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>


    <div class="btn-group-sm" id="toolbar_1" role="group">
      <div class="btn-group">
        <select class="form-control" data-style="btn-success"  id="cycleIdSelect_1"  th:onchange="changeCycleType_1()">
          <optgroup th:label="#{okr.yearChoice}">
            <div th:each="cycle : ${cycleList}">
              <div th:if="${cycle.cycleType == 1}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
              </div>
            </div>
          </optgroup>
          <optgroup th:label="#{okr.quarterChoice}">
            <div th:each="cycle : ${cycleList}">
              <div th:if="${cycle.cycleType == 0}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
              </div>
            </div>
          </optgroup>
        </select>
      </div>
    </div>

    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table-update"></table>
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="ibox-content">
                        <div class="echarts" id="echarts-pie-chart" _echarts_instance_="ec_1634454955988" style="-webkit-tap-highlight-color: transparent; user-select: none; position: relative;"><div style="position: relative; overflow: hidden; width: 366px; height: 240px; padding: 0px; margin: 0px; border-width: 0px; cursor: default;"><canvas data-zr-dom-id="zr_0" width="457" height="300" style="position: absolute; left: 0px; top: 0px; width: 366px; height: 240px; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); padding: 0px; margin: 0px; border-width: 0px;"></canvas></div><div></div></div>
                    </div>
                </div>
            </div>

        </div>
  </div>


</div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: comment-js" />
<th:block th:include="include :: qqFace" />
<script src="/ajax/libs/report/sparkline/jquery.sparkline.min.js"></script>
<script src="/ajax/libs/report/echarts/echarts-all.js"></script>
<script th:inline="javascript">
  var prefix = ctx + "operating";

  getCycleId();
  function getCycleId(){
      $.ajax({
          url: ctx + "operating/getCycleId",
          data: {'cycleId' : $("#cycleIdSelect").val()},
          type: 'POST'
      })
  }

  $(function () {
    var options = {
      id: "bootstrap-table",
      url: prefix + "/list",
      ajaxParams:{"cycleId":$("#cycleIdSelect").val()},
      onDblClickRow: onDbClick,
      showSearch:false,
      columns: [
        {
          field: 'selectItem',
          checkbox: false
        },
        {
          field: 'status',
          visible: false
        },
        {
          field: 'statusName',
          title: 'Kr状态'
        },
        {
          field: 'count',
          title: '数量',
        },
        {
          field: 'proportion',
          title: '占比',
          formatter: function (value, row, index) {
            return '<span class="badge badge-success">' + value.toFixed(1)  + '%</span>';
          }
        }
      ]
    };
    $.table.init(options);
  });

  initPie();


  $(function () {
    var options = {
      id: "bootstrap-table-update",
      toolbar: "toolbar_1",
      url: prefix + "/updateCountList",
      ajaxParams:{"cycleId":$("#cycleIdSelect_1").val()},
      // onDblClickRow: onDbClick,
      showSearch:false,
      columns: [
        {
          field: 'userName',
          title: '用户名'
        },
        {
          field: 'updateCount',
          title: '进度修改次数'
        },
          {
              field: 'disDay',
              title: '距离上次更新进度时间 (天)'
          },
        {
          field: 'userId',
          visible: false
        }
      ]
    };
    $.table.init(options);
  });


  function initPie(){

      $.ajax({
          url: ctx + "operating/getList",
          type: 'POST',
          data: {'cycleId' : $("#cycleIdSelect_1").val()},
          success: function(data){
              console.log(data)
              var pieChart = echarts.init(document.getElementById("echarts-pie-chart"));
              var pieoption = {
                  title : {
                      text: '目标更新进度次数占比',
                      x:'center'
                  },
                  tooltip : {
                      trigger: 'item',
                      formatter: "{a} <br/>{b} : {c} 人 ({d}%)"
                  },
                  legend: {
                      orient : 'vertical',
                      x : 'left',
                      data:['从未更新','1-4次','5-8次','9-12次','13次以上']
                  },
                  calculable : true,
                  series : [
                      {
                          name:'目标更新进度次数',
                          type:'pie',
                          radius : '55%',
                          center: ['50%', '60%'],
                          data: data
                      }
                  ]
              };
              pieChart.setOption(pieoption);
              $(window).resize(pieChart.resize);
          }
      })

  }



  function getCycleId_1(){
      $.ajax({
          url: ctx + "operating/getCycleId_1",
          data: {'cycleId' : $("#cycleIdSelect_1").val()},
          type: 'POST'
      })
  }



  function onDbClick(row, $element){
    $.ajax({
      url: ctx + "operating/getWorkStatus",
      type: 'POST',
      success: function(data){
        $.modal.openTab("Kr列表", ctx + "operating/getKrs/" + row.status)
      }
    })

  }

  //OKR 周期切换
  function changeCycleType(type) {
    var cycleId = $("#cycleIdSelect").val();
    getCycleId();
    $("#cycleId").val(cycleId);
    $.table.search();
  }


  function changeCycleType_1(type) {
    var cycleId = $("#cycleIdSelect_1").val();
    $("#cycleId").val(cycleId);
    getCycleId_1();
    initPie();
    $.table.search();
  }

</script>
</body>
</html>